{% extends 'base.html' %}
{% load static %}

{% block title %}Creeps Judge - 编程竞赛平台{% endblock %}

{% block extra_css %}
<style>
        /* 主界面特殊样式 */
        .main-container {
            overflow: hidden;
        }

        .main-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 1rem;
            height: calc(100vh - 80px);
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        .hero {
            text-align: center;
            color: white;
            margin: 4rem 0;
        }
        .hero h1 {
            font-size: 3rem;
            margin-bottom: 1rem;
        }
        .hero p {
            font-size: 1.2rem;
            margin-bottom: 2rem;
            opacity: 0.9;
        }
        .main-content {
            display: flex;
            align-items: center;
            flex: 1;
            gap: 4rem;
            margin: 0;
            padding: 1rem 0;
            min-height: 0;
        }

        .hero-section {
            flex: 1;
            padding: 2rem;
        }

        .hero-section h1 {
            font-size: 4rem;
            background: linear-gradient(135deg, #00d4ff, #6496ff, #ffffff);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            margin-bottom: 1.5rem;
            text-shadow:
                0 0 5px rgba(0, 212, 255, 0.4),
                0 0 10px rgba(0, 212, 255, 0.3),
                0 0 15px rgba(0, 212, 255, 0.2),
                0 0 20px rgba(100, 150, 255, 0.15),
                2px 2px 4px rgba(0, 0, 0, 0.3);
            animation: glow 2s ease-in-out infinite alternate;
            filter: drop-shadow(0 0 8px rgba(0, 212, 255, 0.3));
        }

        @keyframes glow {
             from {
                 text-shadow:
                     0 0 5px rgba(0, 212, 255, 0.4),
                     0 0 10px rgba(0, 212, 255, 0.3),
                     0 0 15px rgba(0, 212, 255, 0.2),
                     0 0 20px rgba(100, 150, 255, 0.15),
                     2px 2px 4px rgba(0, 0, 0, 0.3);
                 filter: drop-shadow(0 0 8px rgba(0, 212, 255, 0.3));
             }
             to {
                 text-shadow:
                     0 0 8px rgba(0, 212, 255, 0.6),
                     0 0 15px rgba(0, 212, 255, 0.4),
                     0 0 22px rgba(0, 212, 255, 0.3),
                     0 0 28px rgba(100, 150, 255, 0.2),
                     2px 2px 4px rgba(0, 0, 0, 0.3);
                 filter: drop-shadow(0 0 12px rgba(0, 212, 255, 0.4));
             }
         }

        .hero-section p {
            font-size: 1.5rem;
            color: rgba(255, 255, 255, 0.9);
            margin-bottom: 2rem;
            line-height: 1.6;
        }

        .features {
            flex: 1;
            display: flex;
            flex-direction: column;
            gap: 1rem;
            padding: 2rem;
            max-height: 100%;
            overflow: hidden;
        }
        .feature-card {
            background: linear-gradient(135deg, rgba(0, 0, 0, 0.8) 0%, rgba(30, 30, 60, 0.9) 100%);
            -webkit-backdrop-filter: blur(15px);
            backdrop-filter: blur(15px);
            padding: 1rem;
            border-radius: 12px;
            color: white;
            position: relative;
            transition: all 0.3s ease;
            border: 2px solid;
            border-image: linear-gradient(135deg, rgba(255, 255, 255, 0.4), rgba(100, 150, 255, 0.6)) 1;
            overflow: hidden;
            display: flex;
            align-items: center;
            gap: 1rem;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
            flex: 1;
            min-height: 0;
        }

        .feature-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
            transition: left 0.5s ease;
        }

        .feature-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
        }

        /* 新增：下载按钮样式 */
        .download-section {
            background: linear-gradient(135deg, rgba(30, 60, 90, 0.9), rgba(20, 40, 70, 0.9));
        }

        .download-buttons {
            display: flex;
            gap: 8px;
            margin-top: 10px;
            flex-wrap: wrap;
        }

        .download-btn {
            padding: 6px 12px;
            border-radius: 6px;
            text-decoration: none;
            color: white;
            font-size: 0.8em;
            font-weight: 500;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 4px;
            border: 1px solid rgba(255, 255, 255, 0.2);
        }

        .lua-btn,
        .python-btn,
        .js-btn,
        .ts-btn {
            background: linear-gradient(135deg, #4A90E2, #357ABD);
        }

        .download-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
            border-color: rgba(255, 255, 255, 0.4);
        }

        .download-btn i {
            font-size: 0.9em;
        }
        .feature-card:hover {
            background: linear-gradient(135deg, rgba(100, 150, 255, 0.2), rgba(255, 255, 255, 0.1));
            border-image: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(100, 150, 255, 1)) 1;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(100, 150, 255, 0.4), 0 0 20px rgba(255, 255, 255, 0.2);
        }

        .feature-card:hover::before {
            left: 100%;
        }

        .feature-card:hover h3 {
            color: #6496ff;
        }

        /* 通用3D卡牌效果类 - 可在其他页面引用 */
        .card-3d {
            position: relative;
            transform-style: preserve-3d;
            transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            overflow: hidden;
        }

        .card-3d::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 15px;
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .card-3d:hover {
            transform: perspective(1000px) rotateX(5deg) rotateY(5deg) translateZ(10px);
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2),
                        0 0 20px rgba(255, 255, 255, 0.1),
                        inset 0 0 15px rgba(255, 255, 255, 0.05);
        }

        .card-3d:hover::after {
            opacity: 1;
        }


        .feature-icon {
            font-size: 2.5rem;
            min-width: 60px;
        }

        .feature-content {
            flex: 1;
        }

        .feature-card h3 {
            margin: 0 0 0.5rem 0;
            font-size: 1.3rem;
            font-weight: bold;
            color: rgba(255, 255, 255, 0.95);
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
            transition: color 0.3s ease;
        }

        .feature-card p {
            margin: 0;
            color: rgba(255, 255, 255, 0.8);
            font-size: 0.95rem;
            line-height: 1.4;
        }
        .btn {
            display: inline-block;
            padding: 0.75rem 1.5rem;
            background: rgba(255, 255, 255, 0.2);
            color: white;
            text-decoration: none;
            border-radius: 8px;
            transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            border: 2px solid rgba(255, 255, 255, 0.3);
            position: relative;
            transform-style: preserve-3d;
            overflow: hidden;
        }



        .btn:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: perspective(500px) rotateX(5deg) rotateY(5deg) translateZ(10px) translateY(-2px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2),
                        0 0 20px rgba(255, 255, 255, 0.3);
        }



        .btn-primary {
            background: rgba(255, 255, 255, 0.9);
            color: #333;
        }



        .btn-primary:hover {
            background: white;
            color: #333;
        }


        .messages {
            margin: 0.5rem 0;
            flex-shrink: 0;
        }
        .alert {
            padding: 1rem;
            border-radius: 5px;
            margin-bottom: 1rem;
        }
        .alert-success {
            background-color: rgba(212, 237, 218, 0.9);
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        /* 队列状态显示样式 - 优化版本 */
        .queue-status-section {
            margin: 3rem 0 2rem 0;
            width: 100%;
            position: relative;
        }

        .queue-status-card {
            background: linear-gradient(135deg, 
                rgba(15, 25, 45, 0.95) 0%, 
                rgba(25, 35, 65, 0.95) 50%, 
                rgba(35, 45, 85, 0.95) 100%);
            -webkit-backdrop-filter: blur(20px);
            backdrop-filter: blur(20px);
            border-radius: 20px;
            padding: 2rem;
            color: white;
            box-shadow: 
                0 12px 40px rgba(0, 0, 0, 0.4),
                0 4px 20px rgba(100, 150, 255, 0.1),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(100, 150, 255, 0.3);
            position: relative;
            overflow: hidden;
            transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        }

        .queue-status-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, 
                transparent, 
                rgba(100, 150, 255, 0.1), 
                transparent);
            transition: left 0.8s ease;
        }

        .queue-status-card:hover {
            transform: translateY(-5px);
            box-shadow: 
                0 20px 60px rgba(0, 0, 0, 0.5),
                0 8px 30px rgba(100, 150, 255, 0.2),
                inset 0 1px 0 rgba(255, 255, 255, 0.2);
            border-color: rgba(100, 150, 255, 0.5);
        }

        .queue-status-card:hover::before {
            left: 100%;
        }

        .queue-status-card h3 {
            text-align: center;
            margin-bottom: 2rem;
            color: #6496ff;
            font-size: 1.4rem;
            font-weight: 600;
            text-shadow: 0 0 15px rgba(100, 150, 255, 0.4);
            position: relative;
        }

        .queue-status-card h3 i {
            margin-right: 0.5rem;
            animation: pulse 2s ease-in-out infinite;
        }

        @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.7; }
        }

        .queue-status-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            grid-template-rows: repeat(2, 1fr);
            gap: 1.2rem;
            margin-bottom: 1.5rem;
        }

        .status-item {
            padding: 1.2rem;
            border-radius: 15px;
            background: linear-gradient(135deg, 
                rgba(255, 255, 255, 0.08) 0%, 
                rgba(100, 150, 255, 0.05) 100%);
            border: 1px solid rgba(100, 150, 255, 0.25);
            text-align: center;
            transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            position: relative;
            overflow: hidden;
            cursor: pointer;
        }

        .status-item::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(135deg, 
                rgba(100, 150, 255, 0.1), 
                rgba(255, 255, 255, 0.05));
            opacity: 0;
            transition: opacity 0.3s ease;
        }

        .status-item:hover {
            background: linear-gradient(135deg, 
                rgba(255, 255, 255, 0.15) 0%, 
                rgba(100, 150, 255, 0.1) 100%);
            border-color: rgba(100, 150, 255, 0.5);
            transform: translateY(-3px) scale(1.02);
            box-shadow: 
                0 8px 25px rgba(0, 0, 0, 0.3),
                0 0 20px rgba(100, 150, 255, 0.2);
        }

        .status-item:hover::before {
            opacity: 1;
        }

        .status-item:active {
            transform: translateY(-1px) scale(1.01);
        }

        .status-number {
            font-size: 2.2rem;
            font-weight: 700;
            color: #6496ff;
            margin-bottom: 0.5rem;
            text-shadow: 
                0 0 15px rgba(100, 150, 255, 0.4),
                0 2px 4px rgba(0, 0, 0, 0.3);
            transition: all 0.3s ease;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        .status-item:hover .status-number {
            color: #7db4ff;
            text-shadow: 
                0 0 20px rgba(100, 150, 255, 0.6),
                0 2px 4px rgba(0, 0, 0, 0.3);
            transform: scale(1.1);
        }

        .status-label {
            font-size: 0.95rem;
            color: rgba(255, 255, 255, 0.85);
            font-weight: 500;
            letter-spacing: 0.5px;
            transition: color 0.3s ease;
        }

        .status-item:hover .status-label {
            color: rgba(255, 255, 255, 0.95);
        }

        .queue-status-footer {
            text-align: center;
            color: rgba(255, 255, 255, 0.6);
            font-size: 0.9rem;
            padding-top: 1rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
        }

        #refresh-icon {
            animation: none;
            transition: transform 0.3s ease;
        }

        #refresh-icon.spinning {
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }

        /* 响应式设计 - 增强版本 */
        
        /* 大屏幕优化 (1200px+) */
        @media (min-width: 1200px) {
            .queue-status-card {
                padding: 2.5rem;
            }
            
            .queue-status-grid {
                gap: 1.5rem;
            }
            
            .status-item {
                padding: 1.5rem;
            }
            
            .status-number {
                font-size: 2.5rem;
            }
        }

        /* 中等屏幕 (768px - 1199px) */
        @media (max-width: 1199px) and (min-width: 769px) {
            .queue-status-card {
                padding: 1.8rem;
            }
            
            .queue-status-grid {
                gap: 1rem;
            }
            
            .status-number {
                font-size: 2rem;
            }
        }

        /* 平板设备 (481px - 768px) */
        @media (max-width: 768px) and (min-width: 481px) {
            .main-content {
                flex-direction: column;
                gap: 2rem;
                min-height: auto;
            }

            .hero-section h1 {
                font-size: 2.5rem;
            }

            .hero-section p {
                font-size: 1.2rem;
            }

            .features {
                padding: 1rem;
            }

            .feature-card {
                padding: 1rem;
            }

            .feature-icon {
                font-size: 2rem;
                min-width: 50px;
            }

            .queue-status-section {
                margin: 2rem 0 1.5rem 0;
            }

            .queue-status-card {
                padding: 1.5rem;
                border-radius: 15px;
            }

            .queue-status-grid {
                grid-template-columns: repeat(2, 1fr);
                gap: 1rem;
            }

            .status-item {
                padding: 1rem;
                border-radius: 12px;
            }

            .status-number {
                font-size: 1.8rem;
            }

            .status-label {
                font-size: 0.85rem;
            }
        }

        /* 手机设备 (320px - 480px) */
        @media (max-width: 480px) {
            .main-content {
                flex-direction: column;
                gap: 1.5rem;
                min-height: auto;
                padding: 0.5rem 0;
            }

            .hero-section {
                padding: 1rem;
            }

            .hero-section h1 {
                font-size: 2rem;
            }

            .hero-section p {
                font-size: 1rem;
                line-height: 1.5;
            }

            .features {
                padding: 0.5rem;
            }

            .feature-card {
                padding: 0.8rem;
                flex-direction: column;
                text-align: center;
                gap: 0.5rem;
            }

            .feature-icon {
                font-size: 1.8rem;
                min-width: auto;
            }

            .queue-status-section {
                margin: 1.5rem 0 1rem 0;
            }

            .queue-status-card {
                padding: 1rem;
                border-radius: 12px;
                margin: 0 0.5rem;
            }

            .queue-status-card h3 {
                font-size: 1.1rem;
                margin-bottom: 1rem;
            }

            .queue-status-grid {
                grid-template-columns: 1fr;
                grid-template-rows: repeat(4, 1fr);
                gap: 0.8rem;
                margin-bottom: 1rem;
            }

            .status-item {
                padding: 0.8rem;
                border-radius: 10px;
            }

            .status-number {
                font-size: 1.5rem;
                margin-bottom: 0.3rem;
            }

            .status-label {
                font-size: 0.8rem;
            }

            .queue-status-footer {
                font-size: 0.8rem;
                padding-top: 0.8rem;
            }
        }

        /* 超小屏幕 (最大320px) */
        @media (max-width: 320px) {
            .queue-status-card {
                margin: 0 0.25rem;
                padding: 0.8rem;
            }

            .status-item {
                padding: 0.6rem;
            }

            .status-number {
                font-size: 1.3rem;
            }

            .status-label {
                font-size: 0.75rem;
            }
        }

        /* 兼容性处理 */
        
        /* 不支持backdrop-filter的浏览器 */
        @supports not (backdrop-filter: blur(20px)) {
            .queue-status-card {
                background: linear-gradient(135deg, 
                    rgba(15, 25, 45, 0.98) 0%, 
                    rgba(25, 35, 65, 0.98) 50%, 
                    rgba(35, 45, 85, 0.98) 100%);
            }
        }

        /* 不支持CSS Grid的浏览器 */
        @supports not (display: grid) {
            .queue-status-grid {
                display: flex;
                flex-wrap: wrap;
                justify-content: space-between;
            }

            .status-item {
                width: calc(50% - 0.6rem);
                margin-bottom: 1rem;
            }

            @media (max-width: 480px) {
                .status-item {
                    width: 100%;
                }
            }
        }

        /* 减少动画效果 (用户偏好) */
        @media (prefers-reduced-motion: reduce) {
            .queue-status-card,
            .status-item,
            .status-number,
            .queue-status-card h3 i {
                animation: none;
                transition: none;
            }

            .queue-status-card:hover,
            .status-item:hover {
                transform: none;
            }
        }

        /* 高对比度模式 */
        @media (prefers-contrast: high) {
            .queue-status-card {
                border: 2px solid #ffffff;
                background: rgba(0, 0, 0, 0.9);
            }

            .status-item {
                border: 1px solid #ffffff;
                background: rgba(255, 255, 255, 0.1);
            }

            .status-number {
                color: #ffffff;
                text-shadow: none;
            }

            .status-label {
                color: #ffffff;
            }
        }
    </style>
{% endblock %}

{% block content %}
    <div class="main-container">

        <div class="main-content">
            <div class="hero-section">
                <h1>Creeps Judge</h1>
                <p>专业的双人对战判题平台<br>支持多种编程语言<br>挑战你的编程技能与策略思维</p>

                <!-- 队列状态显示 -->
                {% if user.is_authenticated %}
                <div class="queue-status-section">
                    <div class="queue-status-card">
                        <h3><i class="fas fa-chart-bar"></i> 对战队列状态</h3>
                        <div class="queue-status-grid">
                            <div class="status-item">
                                <div class="status-number" id="in-progress-count">0</div>
                                <div class="status-label">进行中</div>
                            </div>
                            <div class="status-item">
                                <div class="status-number" id="waiting-count">0</div>
                                <div class="status-label">队列等待</div>
                            </div>
                            <div class="status-item">
                                <div class="status-number" id="total-capacity-count">10</div>
                                <div class="status-label">队列容量</div>
                            </div>
                            <div class="status-item">
                                <div class="status-number" id="max-concurrent-count">3</div>
                                <div class="status-label">最大并发</div>
                            </div>
                        </div>
                        <div class="queue-status-footer">
                            <small>
                                <i class="fas fa-sync-alt" id="refresh-icon"></i>
                                最后更新: <span id="last-update-time">-</span>
                            </small>
                        </div>
                    </div>
                </div>
                {% endif %}

                {% if not user.is_authenticated %}
                    <a href="{% url 'accounts:signup' %}" class="btn btn-primary">立即开始你的编程之旅</a>
                {% endif %}
            </div>

            <div class="features">
                {% if user.is_authenticated %}
                    {% if not user.is_staff %}
                        {% if code_operations_enabled %}
                        <a href="{% url 'codes:code_create' %}" class="feature-card" style="text-decoration: none; color: inherit;">
                            <div class="feature-icon">💾</div>
                            <div class="feature-content">
                                <h3>上传代码</h3>
                                <p>便捷的代码上传、保存和管理功能，让你专注于算法实现</p>
                            </div>
                        </a>
                        {% else %}
                        <div class="feature-card disabled" onclick="showCodeOperationsDisabledAlert()" style="opacity: 0.5; cursor: pointer;" title="点击查看详情">
                            <div class="feature-icon">💾</div>
                            <div class="feature-content">
                                <h3>上传代码</h3>
                                <p>该功能暂时不可用</p>
                            </div>
                        </div>
                        {% endif %}
                        {% if battle_creation_enabled %}
                        <a href="{% url 'battles:battle_create' %}" class="feature-card" style="text-decoration: none; color: inherit;">
                            <div class="feature-icon">⚔️</div>
                            <div class="feature-content">
                                <h3>开始对战</h3>
                                <p>双人实时对战模式，挑战你的编程技能和策略思维</p>
                            </div>
                        </a>
                        {% else %}
                        <div class="feature-card disabled" onclick="showFeatureDisabledAlert()" style="opacity: 0.5; cursor: pointer;" title="点击查看详情">
                            <div class="feature-icon">⚔️</div>
                            <div class="feature-content">
                                <h3>开始对战</h3>
                                <p>该功能暂时不可用</p>
                            </div>
                        </div>
                        {% endif %}
                        <a href="{% url 'battles:battle_list' %}" class="feature-card" style="text-decoration: none; color: inherit;">
                            <div class="feature-icon">📊</div>
                            <div class="feature-content">
                                <h3>查看历史</h3>
                                <p>详细的历史记录和数据分析，追踪你的进步轨迹</p>
                            </div>
                        </a>
                    {% endif %}

                    <a href="{% url 'battles:battle_ranking' %}" class="feature-card" style="text-decoration: none; color: inherit;">
                        <div class="feature-icon">🏆</div>
                        <div class="feature-content">
                            <h3>排行榜</h3>
                            <p>查看全球排名，与其他开发者一较高下</p>
                        </div>
                    </a>
                    <a href="{% url 'api_docs:home' %}" class="feature-card" style="text-decoration: none; color: inherit;">
                        <div class="feature-icon">📚</div>
                        <div class="feature-content">
                            <h3>API 文档</h3>
                            <p>高级API接口文档，简化游戏编程体验</p>
                        </div>
                    </a>

                    {% if user.is_staff %}
                        <!-- 管理员专用功能 -->
                        <a href="{% url 'battles:battle_list' %}" class="feature-card" style="text-decoration: none; color: inherit;">
                            <div class="feature-icon">🛠️</div>
                            <div class="feature-content">
                                <h3>管理对战</h3>
                                <p>管理和监控所有对战记录，维护平台秩序</p>
                            </div>
                        </a>
                        <a href="{% url 'accounts:admin_feature_switches' %}" class="feature-card" style="text-decoration: none; color: inherit;">
                            <div class="feature-icon">🔧</div>
                            <div class="feature-content">
                                <h3>功能开关</h3>
                                <p>管理系统功能的启用和禁用状态</p>
                            </div>
                        </a>
                        <a href="/admin/" class="feature-card" style="text-decoration: none; color: inherit;">
                            <div class="feature-icon">⚙️</div>
                            <div class="feature-content">
                                <h3>系统管理</h3>
                                <p>访问Django管理后台，进行系统配置和用户管理</p>
                            </div>
                        </a>
                    {% endif %}

                    <!-- 编程语言模板下载区域 -->
                    <div class="feature-card">
                        <div class="feature-icon">📦</div>
                        <div class="feature-content">
                            <h3>编程语言模板</h3>
                            <p>下载完整的编程语言模板包，包含项目结构和示例代码</p>
                            <div class="download-buttons">
                                <a href="{% url 'api_docs:download_template' 'python' %}" class="download-btn python-btn">
                                    <i class="fas fa-download"></i> Python 模板
                                </a>
                                <a href="{% url 'api_docs:download_template' 'javascript' %}" class="download-btn js-btn">
                                    <i class="fas fa-download"></i> JavaScript 模板
                                </a>
                                <a href="{% url 'api_docs:download_template' 'typescript' %}" class="download-btn ts-btn">
                                    <i class="fas fa-download"></i> TypeScript 模板
                                </a>
                                <a href="{% url 'api_docs:download_template' 'lua' %}" class="download-btn lua-btn">
                                    <i class="fas fa-download"></i> Lua 模板
                                </a>
                            </div>
                        </div>
                    </div>
                {% else %}
                    <div class="feature-card">
                        <div class="feature-icon">🚀</div>
                        <div class="feature-content">
                            <h3>多语言支持</h3>
                            <p>支持 Python、Lua、JavaScript 等多种编程语言</p>
                        </div>
                    </div>
                    <div class="feature-card">
                        <div class="feature-icon">⚔️</div>
                        <div class="feature-content">
                            <h3>实时对战</h3>
                            <p>双人实时对战模式，挑战你的编程技能和策略思维</p>
                        </div>
                    </div>
                    <div class="feature-card">
                        <div class="feature-icon">📊</div>
                        <div class="feature-content">
                            <h3>数据统计</h3>
                            <p>详细的历史记录和排行榜系统，追踪你的进步轨迹</p>
                        </div>
                    </div>
                    <div class="feature-card">
                        <div class="feature-icon">💾</div>
                        <div class="feature-content">
                            <h3>代码管理</h3>
                            <p>便捷的代码上传、保存和管理功能</p>
                        </div>
                    </div>
                    <a href="{% url 'api_docs:home' %}" class="feature-card" style="text-decoration: none; color: inherit;">
                        <div class="feature-icon">📚</div>
                        <div class="feature-content">
                            <h3>API 文档</h3>
                            <p>高级API接口文档，简化游戏编程体验</p>
                        </div>
                    </a>
                {% endif %}
            </div>
        </div>
    </div>

<script>
    // 显示功能禁用提示
    function showFeatureDisabledAlert() {
        alert('创建对战功能已被管理员暂时关闭。\n\n如有疑问，请联系系统管理员。');
    }

    // 显示代码操作功能禁用提示
    function showCodeOperationsDisabledAlert() {
        alert('代码操作功能已被管理员暂时关闭。\n\n如有疑问，请联系系统管理员。');
    }

    // 更新队列状态 v2
    function updateQueueStatusV2() {
        const refreshIcon = document.getElementById('refresh-icon');
        if (refreshIcon) {
            refreshIcon.classList.add('spinning');
        }

        fetch('/battles/api/manual-battle-queue/status/?t=' + Date.now())
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    // 获取实际的数据对象
                    const apiData = data.data || {};
                    
                    // 更新进行中数量（没有数据时显示0）
                    const inProgressElement = document.getElementById('in-progress-count');
                    if (inProgressElement) {
                        inProgressElement.textContent = apiData.in_progress || 0;
                    }

                    // 更新队列等待数量（没有数据时显示0）
                    const waitingElement = document.getElementById('waiting-count');
                    if (waitingElement) {
                        waitingElement.textContent = apiData.waiting_in_queue || 0;
                    }

                    // 更新总容量（显示配置的10）
                    const totalCapacityElement = document.getElementById('total-capacity-count');
                    if (totalCapacityElement) {
                        totalCapacityElement.textContent = apiData.total_capacity || 10;
                    }

                    // 更新最大并发数（显示配置的3）
                    const maxConcurrentElement = document.getElementById('max-concurrent-count');
                    if (maxConcurrentElement) {
                        maxConcurrentElement.textContent = apiData.max_concurrent || 3;
                    }

                    // 更新最后更新时间
                    const lastUpdateElement = document.getElementById('last-update-time');
                    if (lastUpdateElement) {
                        const now = new Date();
                        lastUpdateElement.textContent = now.toLocaleTimeString();
                    }
                } else {
                    // API调用失败时显示默认值
                    const inProgressElement = document.getElementById('in-progress-count');
                    if (inProgressElement) inProgressElement.textContent = 0;

                    const waitingElement = document.getElementById('waiting-count');
                    if (waitingElement) waitingElement.textContent = 0;

                    const totalCapacityElement = document.getElementById('total-capacity-count');
                    if (totalCapacityElement) totalCapacityElement.textContent = 10;

                    const maxConcurrentElement = document.getElementById('max-concurrent-count');
                    if (maxConcurrentElement) maxConcurrentElement.textContent = 3;
                }
            })
            .catch(error => {
                console.error('获取队列状态失败:', error);
                // 网络错误时也显示默认值
                const inProgressElement = document.getElementById('in-progress-count');
                if (inProgressElement) inProgressElement.textContent = 0;

                const waitingElement = document.getElementById('waiting-count');
                if (waitingElement) waitingElement.textContent = 0;

                const totalCapacityElement = document.getElementById('total-capacity-count');
                if (totalCapacityElement) totalCapacityElement.textContent = 10;

                const maxConcurrentElement = document.getElementById('max-concurrent-count');
                if (maxConcurrentElement) maxConcurrentElement.textContent = 3;
            })
            .finally(() => {
                if (refreshIcon) {
                    refreshIcon.classList.remove('spinning');
                }
            });
    }

    // 页面加载完成后初始化
    document.addEventListener('DOMContentLoaded', function() {
        // 如果用户已登录且队列状态元素存在，则开始更新队列状态
        if (document.getElementById('in-progress-count')) {
            // 页面加载时立即更新一次
            updateQueueStatusV2();
        }
    });
</script>

{% endblock %}